package com.ivm.services;

import com.ivm.view.Event;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

/**
 *
 * @author ivana
 */
@Path("/events")
public class EventService {

    @GET
    @Path("/get")
    @Produces(MediaType.APPLICATION_JSON)
    public ArrayList<Event> getEvents(@QueryParam("username") String userName,
            @QueryParam("startdate") String startDate, @QueryParam("endDate") String endDate) {

        Event event = new Event();
        event.setTitle("JSON TEST");
        event.setAllDay(true);
        event.setStart(Calendar.getInstance().getTime().toGMTString());
        event.setEnd(Calendar.getInstance().getTime().toGMTString());
        event.setId(1l);

        Event event2 = new Event();
        event2.setTitle("JSON TEST2");
        event2.setAllDay(true);
        event2.setStart(Calendar.getInstance().getTime().toGMTString());
        event2.setEnd(Calendar.getInstance().getTime().toGMTString());
        event2.setId(2l);

        ArrayList<Event> events = new ArrayList<>();
        events.add(event);
        events.add(event2);
        
        List<String> fm = lookup("FrontendManager").findUsers("123", "1234");
        System.out.println("--------" + fm.get(0));
        return events;

    }
    
    public FrontendManager lookup(String className) {
        try {
            InitialContext context = new InitialContext();
            return (FrontendManager) context.lookup("com.ivm.services.FrontendManager");
        } catch (NamingException ex) {
            Logger.getLogger(EventService.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
}
